//
//  WKPopView.m
//  danpin
//
//  Created by chuangjia on 11/9/15.
//  Copyright (c) 2015 chuangjia. All rights reserved.
//

#import "WKPopView.h"
#import "BaseCell.h"
#define WKRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
//按钮颜色
#define OKBUTTON_BGCOLOR AlertRGB(0x1666C8)
#define CANCELBUTTON_BGCOLOR AlertRGB(0xf8f8f8)
//按钮起始tag
#define TAG 100

#define SCREEN_Width   [UIScreen mainScreen].bounds.size.width
#define SCREEN_Height   [UIScreen mainScreen].bounds.size.height
@interface WKPopView ()
{
   
}
@property(nonatomic,strong) UILabel *title;
@property(nonatomic,strong) UILabel *subtitle;
@end
@implementation WKPopView
@synthesize title=_title;
@synthesize subtitle=_subtitle;
+ (instancetype)showAlertViewWithTitle:(NSString *)title subTitle:(NSString*)subtitle callBlock:(callBack1)callBack
{
    [[self shared] addTitle:title detail:subtitle];
    [[self shared] setClickBlock:nil];//释放掉之前的Block
    [[self shared] setClickBlock:callBack];
    [[self shared] setHidden:NO];//设置为不隐藏
    return  [self shared];
 }
//单例
+ (instancetype)shared
{
    static dispatch_once_t once = 0;
    static WKPopView *alert;
    dispatch_once(&once, ^{
        alert = [[WKPopView alloc] init];
    });
    return alert;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.frame = (CGRect) {{0.f,0.f}, [[UIScreen mainScreen] bounds].size};
        self.alpha = 1;
        [self setBackgroundColor:[UIColor clearColor]];
        self.hidden = NO;//不隐藏
        self.windowLevel = 1000;
        
        [self initui];
    }
    
    return self;
}
-(void)dealloc
{
    self.subtitle=nil;
    self.title=nil;
}
-(void)initui
{
    UIImage *image =[UIImage imageNamed:@"windows_bg.png"];
    UIView *sview =[[UIView alloc] initWithFrame:CGRectMake(0, 0,widthAuto(image.size.width) ,hightAuto(image.size.height) )];
    sview.backgroundColor=[UIColor clearColor];
    sview.center=self.center;
    //
    UIImageView *imageview =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, widthAuto(image.size.width), hightAuto(image.size.height))];
    imageview.image=image;
    [sview addSubview:imageview];
    imageview=nil;
    
    UIImage *image1 =[UIImage imageNamed:@"windows_shaidan_icon.png"];
    UIImageView *imageview1 =[[UIImageView alloc] initWithFrame:CGRectMake((widthAuto(image.size.width)-widthAuto(image1.size.width))/2, hightAuto(40), widthAuto(image1.size.width), hightAuto(image1.size.height))];
    imageview1.image=image1;
    [sview addSubview:imageview1];
    
    //title
    _title =[[UILabel alloc] initWithFrame:CGRectMake(0, imageview1.frame.origin.y+imageview1.frame.size.height+30, widthAuto(image.size.width), hightAuto(20))];
    _title.backgroundColor = [UIColor clearColor];
    _title.textColor = [UIColor whiteColor];
    _title.textAlignment = NSTextAlignmentCenter;
    _title.font = FONT(20);
    [sview addSubview:_title];
   
    
    //subtilte
    _subtitle =[[UILabel alloc] initWithFrame:CGRectMake(0, _title.frame.origin.y+_title.frame.size.height+10, widthAuto(image.size.width), hightAuto(20))];
    _subtitle.backgroundColor = [UIColor clearColor];
    _subtitle.textColor = [UIColor whiteColor];
    _subtitle.textAlignment = NSTextAlignmentCenter;
    _subtitle.font = FONT(12);
    [sview addSubview:_subtitle];

    imageview1=nil;
    //
    UIButton *cacelbtn =[UIButton buttonWithType:UIButtonTypeCustom];
    cacelbtn.tag=0;
    cacelbtn.backgroundColor =[UIColor clearColor];
     [cacelbtn setTitleColor:UIColorFromRGB(0x808080) forState:UIControlStateNormal];
    cacelbtn.frame =CGRectMake((widthAuto(image.size.width)/2-widthAuto(45))/2,  hightAuto(image.size.height)-hightAuto(21)-32,widthAuto(45) ,hightAuto(21) );
    cacelbtn.titleLabel.font =FONT(15);
    [cacelbtn setTitle:@"知道了" forState:UIControlStateNormal];
    [cacelbtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [sview addSubview:cacelbtn];
    //
    UIButton *okBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    okBtn.backgroundColor =[UIColor clearColor];
    okBtn.tag=1;
    [okBtn setTitleColor:UIColorFromRGB(0x1666C8) forState:UIControlStateNormal];
    okBtn.frame =CGRectMake(widthAuto(image.size.width)/2+widthAuto(60)/2,  hightAuto(image.size.height)-hightAuto(21)-32,widthAuto(60) ,hightAuto(21) );
    okBtn.titleLabel.font =FONT(15);
    [okBtn setTitle:@"查看晒单" forState:UIControlStateNormal];
    [okBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [sview addSubview:okBtn];
    
    //
    [self addSubview:sview];
    sview=nil;
}
- (void)addTitle:(NSString *)title detail:(NSString *)detail
{
    
    _title.text  = title;
    _subtitle.text =detail;
}

- (void)buttonClick:(UIButton *)sender
{
    self.clickBlock(sender.tag);
}

@end
